/*
 * ChooseTaxInvoiceView.java
 * business
 *
 * Created by ChenTao on 2017/1/7.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.shoppingcart.chooseinvoice.tax;

import android.app.Activity;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.TaxInvoice;
import com.yidiandao.business.ui.main.shoppingcart.chooseinvoice.ChooseInvoiceFragment;
import com.yidiandao.business.ui.widget.dialog.LoadingDialog;
import com.yidiandao.business.utils.UIUtils;

/** 选择增值税发票View */
public class ChooseTaxInvoiceView implements ChooseTaxInvoiceContract.View {

    private ChooseTaxInvoiceContract.Presenter mPresenter;

    private Activity mActivity;

    private EditText mEtCompanyName;

    private EditText mEtTaxpayerNumber;

    private EditText mEtRegisterAddress;

    private EditText mEtRegisterNumber;

    private EditText mEtBankName;

    private EditText mEtBankNumber;

    private EditText mEtReceiverName;

    private EditText mEtReceiverNumber;

    private EditText mEtReceiverAddress;
    
    private LoadingDialog mLoadingDialog;

    public ChooseTaxInvoiceView(View taxRoot, Activity activity) {
        mActivity = activity;

        mEtCompanyName = (EditText) taxRoot.findViewById(R.id.et_company_name);
        mEtTaxpayerNumber = (EditText) taxRoot.findViewById(R.id.et_taxpayer_number);
        mEtRegisterAddress = (EditText) taxRoot.findViewById(R.id.et_register_address);
        mEtRegisterNumber = (EditText) taxRoot.findViewById(R.id.et_register_number);
        mEtBankName = (EditText) taxRoot.findViewById(R.id.et_bank_name);
        mEtBankNumber = (EditText) taxRoot.findViewById(R.id.et_bank_number);
        mEtReceiverName = (EditText) taxRoot.findViewById(R.id.et_receiver_name);
        mEtReceiverNumber = (EditText) taxRoot.findViewById(R.id.et_receiver_number);
        mEtReceiverAddress = (EditText) taxRoot.findViewById(R.id.et_receiver_address);
    }

    @Override
    public void refreshUI(TaxInvoice taxInvoice) {
        mEtCompanyName.setText(taxInvoice.getCompanyName());
        mEtTaxpayerNumber.setText(taxInvoice.getTaxCode());
        mEtRegisterAddress.setText(taxInvoice.getRegisterAddress());
        mEtRegisterNumber.setText(taxInvoice.getRegisterPhone());
        mEtBankName.setText(taxInvoice.getBankName());
        mEtBankNumber.setText(taxInvoice.getBankAccount());
        mEtReceiverName.setText(taxInvoice.getReceiceName());
        mEtReceiverNumber.setText(taxInvoice.getReceiveMobile());
        mEtReceiverAddress.setText(taxInvoice.getReceiveAddress());
    }

    @Override
    public void stopInputContent() {
        mEtCompanyName.setInputType(InputType.TYPE_NULL);
        mEtTaxpayerNumber.setInputType(InputType.TYPE_NULL);
        mEtRegisterAddress.setInputType(InputType.TYPE_NULL);
        mEtRegisterNumber.setInputType(InputType.TYPE_NULL);
        mEtBankName.setInputType(InputType.TYPE_NULL);
        mEtBankNumber.setInputType(InputType.TYPE_NULL);
        mEtReceiverName.setInputType(InputType.TYPE_NULL);
        mEtReceiverNumber.setInputType(InputType.TYPE_NULL);
        mEtReceiverAddress.setInputType(InputType.TYPE_NULL);
    }

    @Override
    public String getCompanyName() {
        return mEtCompanyName.getText().toString().trim();
    }

    @Override
    public String getTaxpayerNumber() {
        return mEtTaxpayerNumber.getText().toString().trim();
    }

    @Override
    public String getRegisterAddress() {
        return mEtRegisterAddress.getText().toString().trim();
    }

    @Override
    public String getRegisterNumber() {
        return mEtRegisterNumber.getText().toString().trim();
    }

    @Override
    public String getBankName() {
        return mEtBankName.getText().toString().trim();
    }

    @Override
    public String getBankNumber() {
        return mEtBankNumber.getText().toString().trim();
    }

    @Override
    public String getReceiverName() {
        return mEtReceiverName.getText().toString().trim();
    }

    @Override
    public String getReceiverNumber() {
        return mEtReceiverNumber.getText().toString().trim();
    }

    @Override
    public String getReceiverAddress() {
        return mEtReceiverAddress.getText().toString().trim();
    }

    @Override
    public void showLoadingDialog() {
        if (mLoadingDialog == null) {
            mLoadingDialog = new LoadingDialog(mActivity);
        }
        mLoadingDialog.show();
    }

    @Override
    public void hideLoadingDialog() {
        if (mLoadingDialog != null) {
            mLoadingDialog.dismiss();
        }
    }

    @Override
    public void finishActivity() {
        mActivity.finish();
    }

    @Override
    public void setPresenter(ChooseTaxInvoiceContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getPagerTag() {
        return ChooseInvoiceFragment.class.getSimpleName();
    }

    @Override
    public void showToast(String text) {
        UIUtils.showToast(text);
    }
}
